﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CMS.DataAccess;
using System.Data;
using CMS.BaseEntity;

namespace CMS.BusinessLogic
{
    public class UserLogic
    {
        public static DataTable GetUserLogin(User user)
        {
            return UserAccess.GetUserLogin(user);
        }

        public static DataTable GetUserInfoById(User user)
        {
            return UserAccess.GetUserInfoById(user);
        }

        public static bool Authenticate(User user)
        {
            DataTable dt = GetUserLogin(user);
            if (dt.Rows.Count == 1)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// get role
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static int GetPermission(User user)
        {
            DataTable dt = GetUserInfoById(user);
            if (dt.Rows.Count == 1)
            {
                DataRow dr = dt.Rows[0];
                return int.Parse(dr["Role"].ToString());
            }
            return 0;
        }
    }
}